% apc3 = 0.775000000000000*3;
% apc4 = 0.690000000000000*3;
% apc = [0.100000000000000   0.2000000000000   apc3   apc4];

h = figure(1);
% title(h,'Fitting Result')
set(h, 'Position',  [50 50  1280 720])
% set(gcf, 'Position', [200 231 1000 969])
% Position = [0.696558 0.259107 0.208442 0.192056];
% set(gca, 'Position', [0.12 0.22 .87 .76]);
% [0.696558 0.259107 0.208442 0.192056]
hold on;
set(gca,'position',apc);
subplot(2,2,1)
% COM position
upperBCOMP = XupperB.upperBCOMP;
lowerBCOMP = XlowerB.lowerBCOMP;
x_meanCOMP = Xmean.x_meanCOMP;
OptFit_Combine(ave_time,upperBCOMP ,lowerBCOMP ,x_meanCOMP ,'COM_Position',...
    'COM Position',a_opt(1,:),1,ns_time_mean,1,1)
% non-stance COM slope
subplot(2,2,2)
upperBNSCOM = XupperB.upperBNSCOM;
lowerBNSCOM = XlowerB.lowerBNSCOM;
x_meanNSCOM = Xmean.x_meanNSCOM;
OptFit_Combine(ave_time,upperBNSCOM ,lowerBNSCOM ,x_meanNSCOM ,'ns_COM_Slope',...
    'Slope',a_opt(2,:),2,ns_time_mean,2,2)
% stance knee
subplot(2,2,3)
OptFit_Combine(ave_time,upperBSK ,lowerBSK ,x_meanSK ,'s_knee',...
    'Stance Knee',a_opt(3,:),2,ns_time_mean,7,3)
% non-stance knee
subplot(2,2,4)
OptFit_Combine(ave_time,upperBNSK,lowerBNSK ,x_meanNSK ,'ns_knee',...
    'Nonstance Knee',a_opt(4,:),2,ns_time_mean,6,4)

% title('Fitting Result')
% set(gcf, 'Position', [200 231 1000 969])
% set(gcf, 'Position', [0.1 0.2 0.775000000000000*5 0.690000000000000*5;])
% print(gcf, '-depsc','1')
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% COM position
upperBCOMP = XupperB.upperBCOMP;
lowerBCOMP = XlowerB.lowerBCOMP;
x_meanCOMP = Xmean.x_meanCOMP;
OptFit(ave_time,upperBCOMP ,lowerBCOMP ,x_meanCOMP ,'COM_Position',...
    'COM Position',a_opt(1,:),1,ns_time_mean,1)
% non-stance COM slope
upperBNSCOM = XupperB.upperBNSCOM;
lowerBNSCOM = XlowerB.lowerBNSCOM;
x_meanNSCOM = Xmean.x_meanNSCOM;
OptFit(ave_time,upperBNSCOM ,lowerBNSCOM ,x_meanNSCOM ,'ns_COM_Slope',...
    'Slope',a_opt(2,:),2,ns_time_mean,2)
% stance knee
OptFit(ave_time,upperBSK ,lowerBSK ,x_meanSK ,'s_knee',...
    'Stance Knee Angle(rad)',a_opt(3,:),2,ns_time_mean,7)
% non-stance knee
OptFit(ave_time,upperBNSK,lowerBNSK ,x_meanNSK ,'ns_knee',...
    'Nonstance Knee Angle(rad)',a_opt(4,:),2,ns_time_mean,6)

%%%%%%%%%%%% output combination 2 %%%%%%%%%%%%%%%%%%
%% stance COM slope
upperBSCOM = XupperB.upperBSCOM;
lowerBSCOM = XlowerB.lowerBSCOM;
x_meanSCOM = Xmean.x_meanSCOM;
OptFit(ave_time,upperBSCOM ,lowerBSCOM ,x_meanSCOM ,'st_COM_Slope',...
    'stCOMSlope',a_opt(1,:),1,ns_time_mean,3)

% non-stance COM slope
upperBNSCOM = XupperB.upperBNSCOM;
lowerBNSCOM = XlowerB.lowerBNSCOM;
x_meanNSCOM = Xmean.x_meanNSCOM;
OptFit(ave_time,upperBNSCOM ,lowerBNSCOM ,x_meanNSCOM ,'2ns_COM_Slope',...
    'nsCOMSlope',a_opt(2,:),2,ns_time_mean,2)
% stance COM length
upperBSCOMLen = XupperB.upperBSCOMLen;
lowerBSCOMLen = XlowerB.lowerBSCOMLen;
x_meanSCOMLen = Xmean.x_meanSCOMLen;
OptFit(ave_time,upperBSCOMLen ,lowerBSCOMLen ,x_meanSCOMLen ,'st_COM_Len',...
    'StanceCOMLength(m)',a_opt(3,:),2,ns_time_mean,4)

% non stance COM length
upperBNSCOMLen = XupperB.upperBNSCOMLen;
lowerBNSCOMLen = XlowerB.lowerBNSCOMLen;
x_meanNSCOMLen = Xmean.x_meanNSCOMLen;
OptFit(ave_time,upperBNSCOMLen ,lowerBNSCOMLen ,x_meanNSCOMLen ,'ns_COM_Len',...
    'NonstanceCOMLength(m)',a_opt(4,:),2,ns_time_mean,5)

%%%%%%%%%%%%%%%%%%%%%%%%%%%% output combination 3 %%%%%%%%%%%%%%%%%%
%%
% COM position
upperBCOMP = XupperB.upperBCOMP;
lowerBCOMP = XlowerB.lowerBCOMP;
x_meanCOMP = Xmean.x_meanCOMP;
OptFit(ave_time,upperBCOMP ,lowerBCOMP ,x_meanCOMP ,'3COM_Position',...
    'COM Position',a_opt(1,:),1,ns_time_mean,1)

% non-stance COM slope
upperBNSCOM = XupperB.upperBNSCOM;
lowerBNSCOM = XlowerB.lowerBNSCOM;
x_meanNSCOM = Xmean.x_meanNSCOM;
OptFit(ave_time,upperBNSCOM ,lowerBNSCOM ,x_meanNSCOM ,'3ns_COM_Slope',...
    'nsCOMSlope',a_opt(2,:),2,ns_time_mean,2)

% stance COM length
upperBSCOMLen = XupperB.upperBSCOMLen;
lowerBSCOMLen = XlowerB.lowerBSCOMLen;
x_meanSCOMLen = Xmean.x_meanSCOMLen;
OptFit(ave_time,upperBSCOMLen ,lowerBSCOMLen ,x_meanSCOMLen ,'3st_COM_Len',...
    'StanceCOMLength(m)',a_opt(3,:),2,ns_time_mean,4)

% non stance COM length
upperBNSCOMLen = XupperB.upperBNSCOMLen;
lowerBNSCOMLen = XlowerB.lowerBNSCOMLen;
x_meanNSCOMLen = Xmean.x_meanNSCOMLen;
OptFit(ave_time,upperBNSCOMLen ,lowerBNSCOMLen ,x_meanNSCOMLen ,'3ns_COM_Len',...
    'NonstanceCOMLength(m)',a_opt(4,:),2,ns_time_mean,5)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% output combination 4 %%%%%%%%%%%%
%%
a_opt = a0;
% COM position
upperBCOMP = XupperB.upperBCOMP;
lowerBCOMP = XlowerB.lowerBCOMP;
x_meanCOMP = Xmean.x_meanCOMP;
OptFit(ave_time,upperBCOMP ,lowerBCOMP ,x_meanCOMP ,'4COM_Position',...
    'COM Position',a_opt(1,:),1,ns_time_mean,1)

% COM Angle
upperBCOMangle = XupperB.upperBCOMangle;
lowerBCOMangle = XlowerB.lowerBCOMangle;
x_meanCOMangle = Xmean.x_meanCOMangle;
OptFit(ave_time,upperBCOMangle ,lowerBCOMangle ,x_meanCOMangle ,'4COM_Angle',...
    'COMAngle(rad)',a_opt(2,:),2,ns_time_mean,8)

% stance COM length
upperBSCOMLen = XupperB.upperBSCOMLen;
lowerBSCOMLen = XlowerB.lowerBSCOMLen;
x_meanSCOMLen = Xmean.x_meanSCOMLen;
OptFit(ave_time,upperBSCOMLen ,lowerBSCOMLen ,x_meanSCOMLen ,'4st_COM_Len',...
    'StanceCOMLength(m)',a_opt(3,:),2,ns_time_mean,4)

% non stance COM length
upperBNSCOMLen = XupperB.upperBNSCOMLen;
lowerBNSCOMLen = XlowerB.lowerBNSCOMLen;
x_meanNSCOMLen = Xmean.x_meanNSCOMLen;
OptFit(ave_time,upperBNSCOMLen ,lowerBNSCOMLen ,x_meanNSCOMLen ,'4ns_COM_Len',...
    'NonstanceCOMLength(m)',a_opt(4,:),2,ns_time_mean,5)


%%%%%%%%%%%%%%%%%%%%%%%%%%% output combination 5 %%%%%%%%%%%%%%%%%%%%%%%%%
%% 
a_opt = a0;
% Linearized COM position
upperBCOMPL = XupperB.upperBCOMPL;
lowerBCOMPL = XlowerB.lowerBCOMPL;
x_meanCOMPL = Xmean.x_meanCOMPL;
OptFit(ave_time,upperBCOMPL ,lowerBCOMPL ,x_meanCOMPL ,'COM_Position_L',...
    'Linearized COM Position',a_opt(1,:),1,ns_time_mean,1)
% non-stance COM slope
upperBNSCOML = XupperB.upperBNSCOML;
lowerBNSCOML = XlowerB.lowerBNSCOML;
x_meanNSCOML = Xmean.x_meanNSCOML;
OptFit(ave_time,upperBNSCOML ,lowerBNSCOML ,x_meanNSCOML ,'ns_COM_SlopeL',...
    'Linearized Slope',a_opt(2,:),2,ns_time_mean,2)
% stance knee
OptFit(ave_time,upperBSK ,lowerBSK ,x_meanSK ,'s_knee',...
    'Stance Knee Angle(rad)',a_opt(3,:),2,ns_time_mean,7)
% non-stance knee
OptFit(ave_time,upperBNSK,lowerBNSK ,x_meanNSK ,'ns_knee',...
    'Nonstance Knee Angle(rad)',a_opt(4,:),2,ns_time_mean,6)